import time
from public.action import *
from public.business import *
from public.testData import *
from public.tools import *

testCase = "DBshop009_退款客户信息"

# 实例化浏览器对象，打开指定网页
driver = openBrowser(url)
# 前台登录
DBshopLogin(driver,userName,password)
# 点击我的订单
driver.find_element_by_link_text("我的订单").click()
# 点击退货申请
driver.find_element_by_link_text("退货申请").click()
# 点击申请退货
driver.find_element_by_xpath("//a[@class = 'btn btn-small btn-danger']").click()

rootPath = get_pro_rootpath() #获取项目的绝对路径
filePath = rootPath+r'\public\order1.txt' #拼接文件路径
orderNo = readFile(filePath) #读取文件中的订单编号

# 搜索框输入读取的订单号
driver.find_element_by_id("order_sn").send_keys(orderNo)
# 点击查询按钮
driver.find_element_by_xpath("(//button)[1]").click()
# 选择退款方式
driver.find_element_by_xpath("(//input[@name = 'refund_type'])[1]").click()
# 输入退款说明
driver.find_element_by_id("refund_info").send_keys("有损坏")
# 点击申请退款
driver.find_element_by_xpath("(//button)[2]").click()
# 处理弹框
time.sleep(3)
driver.switch_to.alert.accept()

# 登录后台
driver.get(urlAdmin)
DBshopLoginAdmin(driver)
# 处理二级菜单
DBshopEnterMenu2(driver,"销售管理","退货管理")
# 文本框输入订单号
driver.find_element_by_xpath("//input[@name = 'order_sn']").send_keys(orderNo)
# 定位下拉框
driver.find_element_by_xpath("//select[@name = 'refund_type']/option[2]").click()

# 点击搜索按钮
driver.find_element_by_xpath("(//button)[1]").click()

reuulte = driver.find_element_by_xpath("//tbody/tr[2]/td[1]").text

if reuulte == orderNo:
    writeLog("%s 测试通过" % testCase)
else:
    writeLog("%s 测试不通过" % testCase)
    getPhoto(driver)
driver.quit()





